<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/Dialog.ftl" as Dialog>
<#import "/macro/Card.ftl" as Card>

<@header title="角色授权">

</@header>

<@body>
    <h2 class="module-title">角色授权</h2>

    <div class="alert alert-primary" role="alert">
        <nav class="nav">
            <#--<button class="btn btn-info" onclick="javascript: history.back(-1);return false;">返回</button>-->
            <a class="btn btn-info btn-sm" href="${ctx}/role/list" role="button" aria-pressed="true">返回</a>
            <span style="margin-right: 50px; margin-left: 100px">角色名称:<span style="font-size: 20px; margin-left: 10px">${role.name}</span></span>
        </nav>
    </div>

    <div class="alert alert-info" role="alert">
        <form id="roleAuthorizeForm">
            <div class="accordion" id="accordionExample">
                <ul class="list-group">
                    <#list authorityGroupMap?keys as key>
                        <@Card.Card id="role${key}" title="${key}">
                            <li class="list-group-item">
                                <#list authorityGroupMap[key] as authority>
                                    <div class="form-check form-check-inline">
                                        <input type="checkbox" class="form-check-input" name="authoritys" id="authority${authority.id}" value="${authority.id}" <#if authorityMap["${authority.id}"]??>checked</#if>/>
                                        <label class="form-check-label" for="authority${authority.id}">${authority.description}(${authority.name})</label>
                                    </div>
                                </#list>
                            </li>
                        </@Card.Card>
                    </#list>
                </ul>
            </div>
        <button type="submit" class="btn btn-primary" onclick="saveAuthoritys(${role.id}); return false">保存</button>
        </form>
    </div>

    <@Dialog.Dialog id="roleAuthorizeDialog" title="角色授权">
    </@Dialog.Dialog>
</@body>

<@footer>
    <script>
        function saveAuthoritys(id) {
            $.ajax({
                url:"${ctx}/manager/roleAuthorize/save/json/" + id, //请求的url地址
                dataType:"json", //返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                data: $("#roleAuthorizeForm").serialize(),
                type:"post", //请求方式
                beforeSend:function(){
                    //请求前的处理
                },
                success:function(req){
                    $("#roleAuthorizeDialog .modal-body").text("");
                    if (req.isSuccess) {
                        $("#roleAuthorizeDialog .modal-body").text("保存成功");
                        $('#roleAuthorizeDialog').modal({backdrop: 'static', keyboard: false})
                    } else {
                        $("#roleAuthorizeDialog .modal-body").text("保存成功");
                        $('#roleAuthorizeDialog').modal({backdrop: 'static', keyboard: false})
                    }
                },
                complete:function(){
                    //请求完成的处理
                },
                error:function(){
                    $("#roleAuthorizeDialog .modal-body").text("请求失败");
                    $('#roleAuthorizeDialog').modal({backdrop: 'static', keyboard: false});
                }
            });
        }
    </script>
</@footer>